class Solution {
    public int findLength(int[] A, int[] B) {
        if( A.length==0 || B.length==0 )
            return 0;
        int[][] d = new int[A.length+1][B.length+1];
        int ans =0;
        for(int i=0; i<A.length; i++){
            for(int j=0; j<B.length; j++){
                if( A[i]==B[j] ){
                    d[i+1][j+1] = d[i][j]+1;
                    ans = Math.max(d[i+1][j+1],ans);
                }
            }
        }
        return ans;
    }
}